/**************************
 * \if English
 * @Date:2018.09.10
 * @Author:
 * @Brief:
 * @Detail:
 * @Editor:
 * @Brief:
 * \else
 *
 * @创建日期：2018年9月10日
 * @作者：hualei
 * @大概功能：MODBUS_WRITE指令
**************************/
#include "modbuswriteinstruction.h"

ModbusWrite::ModbusWrite()
{
}

QDataStream& operator <<(QDataStream &out,ModbusWrite &myVector)
{
    if(myVector.writeSourceType == REG_CONST)
    {
        out << (quint32)myVector.instructionType << myVector.robotRegisterIndex <<
            myVector.modbuWriteRegAddress << myVector.busId << (quint32)myVector.modbusType << myVector.jmpLable <<
            myVector.noteStr;
    }
    else if(myVector.writeSourceType == CONST_DATA)
    {
        out << (quint32)myVector.instructionType << myVector.constWriteData << myVector.modbuWriteRegAddress \
            << myVector.busId << (quint32)myVector.modbusType << myVector.jmpLable << myVector.noteStr;
    }

    return out;

}

QDataStream& operator >>(QDataStream &in, ModbusWrite &myVector)
{
    quint32 instructionType;
    quint32 modbusType;
    quint32 valueType;

    in >> instructionType >> myVector.robotRegisterIndex >> valueType >> myVector.modbuWriteRegAddress >> myVector.busId >>
              modbusType >> myVector.jmpLable >> myVector.noteStr;

    myVector.instructionType = (INSTRUCTION_TYPE)instructionType;
    myVector.modbusType = (E_MODBUS_SPEC_TYPE)modbusType;
    myVector.writeSourceType = (VALUE_TYPE)valueType;

    return in;
}
